package com.yunkaweilai.android.net.Glide;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yunkaweilai.android.R;

import java.io.File;

/**
 * Created by Administrator on 2017/6/14.
 */

public class GlideUtils {
    public static void loadImage(Context context, String url,ImageView iv,boolean isflag) {
        //原生 API
        RequestOptions options = new RequestOptions()
                .error(R.mipmap.ic_splash);
        Glide.with(context).load(url).apply(options).into(iv);
    }
    public static void loadImage(Context context, String url, int erroImg, int emptyImg, ImageView iv) {
        //原生 API
        RequestOptions options = new RequestOptions()
                .placeholder(emptyImg)
                .error(erroImg);
        Glide.with(context).load(url).apply(options).into(iv);
    }
    public static void loadNoPlaceImage(Context context, String url, ImageView iv) {
        //原生 API
        Glide.with(context.getApplicationContext()).load(url).into(iv);//没有加加载失败的图片
    }

    public static void loadImage(Context context, String url, ImageView iv) {
        //原生 API
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_img_loading).error(R.mipmap.ic_shop_error);
        Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
    }

    public static void loadImage(Context context, String url, ImageView iv,int error) {
        //原生 API
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_image_in_load).error(error);
        Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
    }

    public static void loadImages(Context context, String url, ImageView iv,int error) {
        //原生 API
        RequestOptions options = new RequestOptions()
                .error(error);
        Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
    }
    public static void loadCircleImage(Context context, String url, ImageView iv,boolean flag) {
        if (flag){
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.ic_image_loading_round).error(R.mipmap.ic_head_man).transform(new GlideCircleTransform(context));
            Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
        }else{
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.ic_image_loading_round).error(R.mipmap.ic_head_woman).transform(new GlideCircleTransform(context));
            Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
        }
    }

    public static void loadCircleImage(Context context, String url, ImageView iv,int error) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_image_loading_round).error(error).transform(new GlideCircleTransform(context));
        Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
    }

    public static void loadCircleImage(Context context, String url, ImageView iv) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_image_loading_round).transform(new GlideCircleTransform(context));
        Glide.with(context.getApplicationContext()).load(url).apply(options).into(iv);
    }

    public static void loadImage(Context context, final File file, final ImageView imageView) {
        Glide.with(context)
                .load(file)
                .into(imageView);


    }

    public static void loadImage(Context context, final int resourceId, final ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_image_loading_round);
        Glide.with(context)
                .load(resourceId)
                .apply(options)
                .into(imageView);
    }

    public static void loadGlideImage(Context context, final int resourceId, final ImageView imageView) {
        Glide.with(context)
                .load(resourceId)
                .into(imageView);
    }
}
